"use strict";
cc._RF.push(module, '4c57e4PAblHBooUQw+FZC4H', 'Subsidy');
// resources/script/business/other/Subsidy.js

"use strict";

var beiMiCommon = require("BeiMiCommon");
cc.Class({
    extends: beiMiCommon,

    onLoad: function onLoad() {
        var self = this;
        if (this.ready()) {
            var socket = this.socket();
            socket.on('subsidy', function (result) {
                self.closeOpenWin();
                var data = self.parse(result);
                if (data != null) {
                    cc.beimi.data.subsidy = data.enable;
                    cc.beimi.data.subtimes = result.subtimes;
                    cc.beimi.data.subgolds = result.subgolds;
                    cc.beimi.data.lefttimes = result.subtimes - result.frequency;

                    self.pva("gold", result.balance);

                    self.updatepva();
                }
                /**
                 * 弹出确认窗口
                 */
                cc.loader.loadRes("prefab/welfare/confirm", function (err, prefab) {
                    cc.beimi.openwin = cc.instantiate(prefab);
                    cc.beimi.openwin.parent = cc.beimi.context.root();
                });
            });
            socket.on('subsidyfaild', function (result) {
                self.closeOpenWin();
                var data = self.parse(result);
                if (data.result != null && data.result != "") {
                    self.alertForCallBack(data.result, function () {
                        self.shopDialog();
                    });
                }
            });
        }
    },
    onClick: function onClick() {
        if (this.ready()) {
            var socket = this.socket();
            var param = {
                command: "subsidy",
                token: cc.beimi.authorization,
                data: cc.beimi.user.id
            };
            socket.emit("command", JSON.stringify(param));
        }
    },
    onDestroy: function onDestroy() {
        if (this.ready()) {
            var socket = this.socket();
            socket.on('subsidy', null);
            socket.on('subsidyfaild', null);
        }
    }
});

cc._RF.pop();